package com.cn.wanxi.service.impl;

import com.cn.wanxi.dao.UserDao;
import com.cn.wanxi.dao.impl.UserImpl;
import com.cn.wanxi.model.ResultModel;
import com.cn.wanxi.model.UserModel;
import com.cn.wanxi.service.UserService;

public class UserServiceImpl implements UserService {
    private UserDao userDao = new UserImpl();

    /**
     * 得到用户名和密码，验证码
     * 1.验证验证码是否正确
     * 2.如果验证码正确   验证用户名和密码是否正确
     * 1.正确
     * 2.不正确
     * 3.不正确 直接返回验证码不正确
     *
     * @param userModel
     * @return
     */
    @Override
    public ResultModel login(UserModel userModel) {
//        ResultModel resultModel = new ResultModel();
        if ("验证码".equals("验证码")) {
//            判断用户名和密码是否正确需要查询数据库，所以需要调用dao层
//            调用dao层返回值应该是数据库的返回值
            UserDao userDao = new UserImpl();
            UserModel model = userDao.findByUsernameAndPassword(userModel);
            if (model == null) {
                return ResultModel.getResult("error");
//                resultModel.setMsg("error");
            } else {
//                resultModel.setMsg("success");
                return ResultModel.getResult("success");
            }
        } else {
//            resultModel.setMsg("error-code");
            return ResultModel.getResult("error-code");
        }
//        resultModel.setCode(1);
//        resultModel.setMsg("登录成功");
//        resultModel.setData("fdasa");
//        resultModel.setCount(1);
//        return resultModel;
    }

    @Override
    public ResultModel add(UserModel userModel) {
//        ResultModel resultModel = new ResultModel();
//        UserDao userDao = new UserImpl();
//        resultModel.setCount(userDao.add(userModel));
//        return resultModel;
        return ResultModel.getResult(userDao.add(userModel));
    }

    @Override
    public ResultModel update(UserModel userModel) {
        return ResultModel.getResult(userDao.update(userModel));
    }

    @Override
    public ResultModel delete(UserModel userModel) {
        return ResultModel.getResult(userDao.delete(userModel));
    }

    @Override
    public ResultModel findById(UserModel userModel) {
        return ResultModel.getResult(userDao.findById(userModel));
    }

    @Override
    public ResultModel findAll(UserModel userModel) {
        return ResultModel.getResult(userDao.findAll(userModel));
    }

    @Override
    public ResultModel getCount(UserModel userModel) {
        return ResultModel.getResult(userDao.getCount(userModel));
    }
}
